package com.flexcloudsdk.taskqueue;

import java.util.logging.Logger;

import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueConstants;
import com.google.appengine.api.taskqueue.QueueFactory;

public class CloudQueueService {
	private static final Logger log = Logger.getLogger(CloudQueueService.class
			.getName());
	@SuppressWarnings("unused")
	private QueueConstants constants = null;
	private String sourceMethod;
	private String sourceClass;

	public CloudQueueService() {
		log.info("CloudQueueService has been created by BlazeDS");
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		sourceClass = CloudQueueService.class.getName();
	}

	public CloudQueue getDefaultQueue() {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);
	
		Queue queue = QueueFactory.getDefaultQueue();
		CloudQueue cloudQueue = new CloudQueue(queue);

		return cloudQueue;
	}

	public CloudQueue getQueue(String queueName) {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);
	
		Queue queue = QueueFactory.getQueue(queueName);
		CloudQueue cloudQueue = new CloudQueue(queue);

		return cloudQueue;
	}

}
